//
//  WarGameDecks.m
//  WarGame
//
//  Created by Jacob V.V. Goldberg on 6/27/12.
//  Copyright (c) 2012 FutureSight Technologies. All rights reserved.
//

#import "WarGameDecks.h"

@interface WarGameDecks()
@property (strong, nonatomic) NSMutableArray *fullDeck;
@property (strong, nonatomic) NSMutableArray *botDeck;
@property (strong, nonatomic) NSMutableArray *playerDeck;
@end

@implementation WarGameDecks
@synthesize fullDeck = _fullDeck;
@synthesize botDeck = _botDeck;
@synthesize playerDeck = _playerDeck;

-(NSMutableArray *) fullDeck {
	//"lazy intitialization"
	if (!_fullDeck) {
		_fullDeck = [NSMutableArray arrayWithCapacity:52];
		for (int i = 0; i < 52; i++) {
			[_fullDeck addObject:[NSNumber numberWithInt:i]];
		}
	}
	return _fullDeck;
}

-(void) shuffleFullDeck {
	for (int i = 0; i < 51; i++) {
		[self.fullDeck exchangeObjectAtIndex:i withObjectAtIndex:arc4random_uniform(51 - i) + i];
	}
	
	//deal the cards already!!!
	NSRange pl = NSMakeRange(0, 26);
	NSRange bo = NSMakeRange(26, 26);
	
	self.playerDeck = [[self.fullDeck subarrayWithRange:pl] mutableCopy];
	self.botDeck = [[self.fullDeck subarrayWithRange:bo] mutableCopy];
}

-(int) pullFromTopOfPlayerDeck {
	int num = [[self.playerDeck objectAtIndex:0] intValue];
	[self.playerDeck removeObjectAtIndex:0];
	return num;
}
-(void) putOnBottomOfPlayerDeck: (int) num {
	[self.playerDeck addObject:[NSNumber numberWithInt:num]];
}
-(int) getPlayerDeckSize; {
	int num = [self.playerDeck count];
	return num;
}

//accessors for BOT
-(int) pullFromTopOfBotDeck {
	int num = [[self.botDeck objectAtIndex:0] intValue];
	[self.botDeck removeObjectAtIndex:0];
	return num;
}
-(void) putOnBottomOfBotDeck: (int) num {
	[self.botDeck addObject:[NSNumber numberWithInt:num]];
}
-(int) getBotDeckSize {
	int num = [self.botDeck count];
	return num;
}


@end